/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.uva.dbcs.practica1.modelo;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author maikel
 */
public class ConexionBD {

    private String SERVER;
    private String PUERTO;
    private String URL;
    private String DATABASE_NAME;
    private String USER;
    private String PASSWORD;
    private Connection conexion = null;
    private final String driverName = "com.mysql.jdbc.Driver";

    public ConexionBD() {
        SERVER = "localhost";
        PUERTO = "3306";
        DATABASE_NAME = "DBCS_Practica1";
        USER = "root";
        PASSWORD = "root";
        URL = "jdbc:mysql://" + SERVER + ":" + PUERTO + "/" + DATABASE_NAME;
    }

    public Connection conectar() throws SQLException, ClassNotFoundException {
        Class.forName(driverName);
        conexion = DriverManager.getConnection(URL, USER, PASSWORD);
        return conexion;
    }

    public void cerrarConexion(Connection connection) throws SQLException {
        connection.close();
    }
}
